/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package gamedsl2.impl;

import gamedsl2.EventTracker;
import gamedsl2.GameHolder;
import gamedsl2.Gamedsl2Package;
import gamedsl2.MapLoader;
import gamedsl2.State;
import gamedsl2.TileShapes;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Game Holder</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link gamedsl2.impl.GameHolderImpl#getStates <em>States</em>}</li>
 *   <li>{@link gamedsl2.impl.GameHolderImpl#getTracker <em>Tracker</em>}</li>
 *   <li>{@link gamedsl2.impl.GameHolderImpl#getMapLoader <em>Map Loader</em>}</li>
 *   <li>{@link gamedsl2.impl.GameHolderImpl#getTileShapes <em>Tile Shapes</em>}</li>
 *   <li>{@link gamedsl2.impl.GameHolderImpl#getName <em>Name</em>}</li>
 *   <li>{@link gamedsl2.impl.GameHolderImpl#isVsync <em>Vsync</em>}</li>
 *   <li>{@link gamedsl2.impl.GameHolderImpl#isFullScreen <em>Full Screen</em>}</li>
 *   <li>{@link gamedsl2.impl.GameHolderImpl#getTargetFps <em>Target Fps</em>}</li>
 *   <li>{@link gamedsl2.impl.GameHolderImpl#getCurrentState <em>Current State</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class GameHolderImpl extends EObjectImpl implements GameHolder {
	/**
	 * The cached value of the '{@link #getStates() <em>States</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getStates()
	 * @generated
	 * @ordered
	 */
	protected EList<State> states;

	/**
	 * The cached value of the '{@link #getTracker() <em>Tracker</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTracker()
	 * @generated
	 * @ordered
	 */
	protected EventTracker tracker;

	/**
	 * The cached value of the '{@link #getMapLoader() <em>Map Loader</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMapLoader()
	 * @generated
	 * @ordered
	 */
	protected EList<MapLoader> mapLoader;

	/**
	 * The cached value of the '{@link #getTileShapes() <em>Tile Shapes</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTileShapes()
	 * @generated
	 * @ordered
	 */
	protected TileShapes tileShapes;

	/**
	 * The default value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected static final String NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected String name = NAME_EDEFAULT;

	/**
	 * The default value of the '{@link #isVsync() <em>Vsync</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isVsync()
	 * @generated
	 * @ordered
	 */
	protected static final boolean VSYNC_EDEFAULT = true;

	/**
	 * The cached value of the '{@link #isVsync() <em>Vsync</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isVsync()
	 * @generated
	 * @ordered
	 */
	protected boolean vsync = VSYNC_EDEFAULT;

	/**
	 * The default value of the '{@link #isFullScreen() <em>Full Screen</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isFullScreen()
	 * @generated
	 * @ordered
	 */
	protected static final boolean FULL_SCREEN_EDEFAULT = false;

	/**
	 * The cached value of the '{@link #isFullScreen() <em>Full Screen</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isFullScreen()
	 * @generated
	 * @ordered
	 */
	protected boolean fullScreen = FULL_SCREEN_EDEFAULT;

	/**
	 * The default value of the '{@link #getTargetFps() <em>Target Fps</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTargetFps()
	 * @generated
	 * @ordered
	 */
	protected static final int TARGET_FPS_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getTargetFps() <em>Target Fps</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTargetFps()
	 * @generated
	 * @ordered
	 */
	protected int targetFps = TARGET_FPS_EDEFAULT;

	/**
	 * The cached value of the '{@link #getCurrentState() <em>Current State</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getCurrentState()
	 * @generated
	 * @ordered
	 */
	protected State currentState;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected GameHolderImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return Gamedsl2Package.Literals.GAME_HOLDER;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<State> getStates() {
		if (states == null) {
			states = new EObjectContainmentEList<State>(State.class, this, Gamedsl2Package.GAME_HOLDER__STATES);
		}
		return states;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EventTracker getTracker() {
		return tracker;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetTracker(EventTracker newTracker, NotificationChain msgs) {
		EventTracker oldTracker = tracker;
		tracker = newTracker;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, Gamedsl2Package.GAME_HOLDER__TRACKER, oldTracker, newTracker);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setTracker(EventTracker newTracker) {
		if (newTracker != tracker) {
			NotificationChain msgs = null;
			if (tracker != null)
				msgs = ((InternalEObject)tracker).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - Gamedsl2Package.GAME_HOLDER__TRACKER, null, msgs);
			if (newTracker != null)
				msgs = ((InternalEObject)newTracker).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - Gamedsl2Package.GAME_HOLDER__TRACKER, null, msgs);
			msgs = basicSetTracker(newTracker, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, Gamedsl2Package.GAME_HOLDER__TRACKER, newTracker, newTracker));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<MapLoader> getMapLoader() {
		if (mapLoader == null) {
			mapLoader = new EObjectContainmentEList<MapLoader>(MapLoader.class, this, Gamedsl2Package.GAME_HOLDER__MAP_LOADER);
		}
		return mapLoader;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public TileShapes getTileShapes() {
		return tileShapes;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetTileShapes(TileShapes newTileShapes, NotificationChain msgs) {
		TileShapes oldTileShapes = tileShapes;
		tileShapes = newTileShapes;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, Gamedsl2Package.GAME_HOLDER__TILE_SHAPES, oldTileShapes, newTileShapes);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setTileShapes(TileShapes newTileShapes) {
		if (newTileShapes != tileShapes) {
			NotificationChain msgs = null;
			if (tileShapes != null)
				msgs = ((InternalEObject)tileShapes).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - Gamedsl2Package.GAME_HOLDER__TILE_SHAPES, null, msgs);
			if (newTileShapes != null)
				msgs = ((InternalEObject)newTileShapes).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - Gamedsl2Package.GAME_HOLDER__TILE_SHAPES, null, msgs);
			msgs = basicSetTileShapes(newTileShapes, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, Gamedsl2Package.GAME_HOLDER__TILE_SHAPES, newTileShapes, newTileShapes));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getName() {
		return name;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setName(String newName) {
		String oldName = name;
		name = newName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, Gamedsl2Package.GAME_HOLDER__NAME, oldName, name));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean isVsync() {
		return vsync;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setVsync(boolean newVsync) {
		boolean oldVsync = vsync;
		vsync = newVsync;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, Gamedsl2Package.GAME_HOLDER__VSYNC, oldVsync, vsync));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean isFullScreen() {
		return fullScreen;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setFullScreen(boolean newFullScreen) {
		boolean oldFullScreen = fullScreen;
		fullScreen = newFullScreen;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, Gamedsl2Package.GAME_HOLDER__FULL_SCREEN, oldFullScreen, fullScreen));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getTargetFps() {
		return targetFps;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setTargetFps(int newTargetFps) {
		int oldTargetFps = targetFps;
		targetFps = newTargetFps;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, Gamedsl2Package.GAME_HOLDER__TARGET_FPS, oldTargetFps, targetFps));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public State getCurrentState() {
		if (currentState != null && currentState.eIsProxy()) {
			InternalEObject oldCurrentState = (InternalEObject)currentState;
			currentState = (State)eResolveProxy(oldCurrentState);
			if (currentState != oldCurrentState) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, Gamedsl2Package.GAME_HOLDER__CURRENT_STATE, oldCurrentState, currentState));
			}
		}
		return currentState;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public State basicGetCurrentState() {
		return currentState;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setCurrentState(State newCurrentState) {
		State oldCurrentState = currentState;
		currentState = newCurrentState;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, Gamedsl2Package.GAME_HOLDER__CURRENT_STATE, oldCurrentState, currentState));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case Gamedsl2Package.GAME_HOLDER__STATES:
				return ((InternalEList<?>)getStates()).basicRemove(otherEnd, msgs);
			case Gamedsl2Package.GAME_HOLDER__TRACKER:
				return basicSetTracker(null, msgs);
			case Gamedsl2Package.GAME_HOLDER__MAP_LOADER:
				return ((InternalEList<?>)getMapLoader()).basicRemove(otherEnd, msgs);
			case Gamedsl2Package.GAME_HOLDER__TILE_SHAPES:
				return basicSetTileShapes(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case Gamedsl2Package.GAME_HOLDER__STATES:
				return getStates();
			case Gamedsl2Package.GAME_HOLDER__TRACKER:
				return getTracker();
			case Gamedsl2Package.GAME_HOLDER__MAP_LOADER:
				return getMapLoader();
			case Gamedsl2Package.GAME_HOLDER__TILE_SHAPES:
				return getTileShapes();
			case Gamedsl2Package.GAME_HOLDER__NAME:
				return getName();
			case Gamedsl2Package.GAME_HOLDER__VSYNC:
				return isVsync();
			case Gamedsl2Package.GAME_HOLDER__FULL_SCREEN:
				return isFullScreen();
			case Gamedsl2Package.GAME_HOLDER__TARGET_FPS:
				return getTargetFps();
			case Gamedsl2Package.GAME_HOLDER__CURRENT_STATE:
				if (resolve) return getCurrentState();
				return basicGetCurrentState();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case Gamedsl2Package.GAME_HOLDER__STATES:
				getStates().clear();
				getStates().addAll((Collection<? extends State>)newValue);
				return;
			case Gamedsl2Package.GAME_HOLDER__TRACKER:
				setTracker((EventTracker)newValue);
				return;
			case Gamedsl2Package.GAME_HOLDER__MAP_LOADER:
				getMapLoader().clear();
				getMapLoader().addAll((Collection<? extends MapLoader>)newValue);
				return;
			case Gamedsl2Package.GAME_HOLDER__TILE_SHAPES:
				setTileShapes((TileShapes)newValue);
				return;
			case Gamedsl2Package.GAME_HOLDER__NAME:
				setName((String)newValue);
				return;
			case Gamedsl2Package.GAME_HOLDER__VSYNC:
				setVsync((Boolean)newValue);
				return;
			case Gamedsl2Package.GAME_HOLDER__FULL_SCREEN:
				setFullScreen((Boolean)newValue);
				return;
			case Gamedsl2Package.GAME_HOLDER__TARGET_FPS:
				setTargetFps((Integer)newValue);
				return;
			case Gamedsl2Package.GAME_HOLDER__CURRENT_STATE:
				setCurrentState((State)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case Gamedsl2Package.GAME_HOLDER__STATES:
				getStates().clear();
				return;
			case Gamedsl2Package.GAME_HOLDER__TRACKER:
				setTracker((EventTracker)null);
				return;
			case Gamedsl2Package.GAME_HOLDER__MAP_LOADER:
				getMapLoader().clear();
				return;
			case Gamedsl2Package.GAME_HOLDER__TILE_SHAPES:
				setTileShapes((TileShapes)null);
				return;
			case Gamedsl2Package.GAME_HOLDER__NAME:
				setName(NAME_EDEFAULT);
				return;
			case Gamedsl2Package.GAME_HOLDER__VSYNC:
				setVsync(VSYNC_EDEFAULT);
				return;
			case Gamedsl2Package.GAME_HOLDER__FULL_SCREEN:
				setFullScreen(FULL_SCREEN_EDEFAULT);
				return;
			case Gamedsl2Package.GAME_HOLDER__TARGET_FPS:
				setTargetFps(TARGET_FPS_EDEFAULT);
				return;
			case Gamedsl2Package.GAME_HOLDER__CURRENT_STATE:
				setCurrentState((State)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case Gamedsl2Package.GAME_HOLDER__STATES:
				return states != null && !states.isEmpty();
			case Gamedsl2Package.GAME_HOLDER__TRACKER:
				return tracker != null;
			case Gamedsl2Package.GAME_HOLDER__MAP_LOADER:
				return mapLoader != null && !mapLoader.isEmpty();
			case Gamedsl2Package.GAME_HOLDER__TILE_SHAPES:
				return tileShapes != null;
			case Gamedsl2Package.GAME_HOLDER__NAME:
				return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
			case Gamedsl2Package.GAME_HOLDER__VSYNC:
				return vsync != VSYNC_EDEFAULT;
			case Gamedsl2Package.GAME_HOLDER__FULL_SCREEN:
				return fullScreen != FULL_SCREEN_EDEFAULT;
			case Gamedsl2Package.GAME_HOLDER__TARGET_FPS:
				return targetFps != TARGET_FPS_EDEFAULT;
			case Gamedsl2Package.GAME_HOLDER__CURRENT_STATE:
				return currentState != null;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (name: ");
		result.append(name);
		result.append(", vsync: ");
		result.append(vsync);
		result.append(", fullScreen: ");
		result.append(fullScreen);
		result.append(", targetFps: ");
		result.append(targetFps);
		result.append(')');
		return result.toString();
	}

} //GameHolderImpl
